using System.Linq;
using Admin3000.Backend.Api.Entity;
using Admin3000.Backend.Api.Params;
using Admin3000.Backend.Api.Repository;
using Admin3000.Backend.Api.Utils;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;

namespace Admin3000.Backend.Api.Controllers
{
    // [Authorize]
    [ApiController]
    [Route("[controller]")]
    public class UserCommentsController : ControllerBase
    {
        private IConfiguration _configuration;

        private IRepository<UserComment> _usercommentRepository;

        private TokenParameter _tokenParameter;

        public UserCommentsController(
            IConfiguration configuration,
            IRepository<UserComment> usercommentRepository
        )
        {
            _configuration = configuration;
            _usercommentRepository = usercommentRepository;
            _tokenParameter =
                _configuration
                    .GetSection("TokenParameter")
                    .Get<TokenParameter>();
        }
        

        //列出用户评论列表
        [HttpGet]
        public dynamic Get()
        {
            var usercomment=_usercommentRepository.Table.ToList();

            return new{
                Code=1000,
                Data=new{Data=usercomment},
                Msg="列出用户评论列表成功"
            };
        }

        
        //新增用户评论  用户Id、评论Id
         [HttpPost]
         [Route("usercommemtID")]
        public dynamic Post(CreateUserComments newUserComments)
        {
            var userid=newUserComments.UserId;
            var commentid=newUserComments.CommentId;
            

            var usercomments = new UserComment{
                UserId=newUserComments.UserId,
                CommentId=newUserComments.CommentId
            };
            _usercommentRepository.Insert(usercomments);
            return new{
                Code = 1000,
                Data=usercomments,
                Msg = "新增用户评论成功"
            };
        }
        //删除对应Id用户评论
        [HttpDelete("{id}")]
        public dynamic Delete(int id)
        {
            _usercommentRepository.Delete(id);
            return new { Code = 1000, Data = "", Msg = "删除用户评论成功^_^" };
        }

    }
}
